package com.company.project.service.impl;

import com.company.project.common.exception.BusinessException;
import com.company.project.common.utils.DateUtils;
import com.company.project.entity.SysDept;
import com.company.project.entity.SysUser;
import com.company.project.service.DeptService;
import com.company.project.service.HttpSessionService;
import com.company.project.service.UserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.company.project.mapper.BusiDangerMapper;
import com.company.project.entity.BusiDangerEntity;
import com.company.project.service.BusiDangerService;

import javax.annotation.Resource;
import java.util.Date;


@Service("busiDangerService")
public class BusiDangerServiceImpl extends ServiceImpl<BusiDangerMapper, BusiDangerEntity> implements BusiDangerService {

    @Resource
    private HttpSessionService httpSessionService;
    @Resource
    private UserService userService;
    @Resource
    private DeptService deptService;
    @Override
    public void wholeAdd(BusiDangerEntity busiDangerEntity) throws BusinessException {
        // 查询当前用户ID
        String userId= httpSessionService.getCurrentUserId();
        busiDangerEntity.setUserId(userId);
        // 查询当前用户所属部门名称
        SysUser user = userService.getById(userId);
        String deptId = user.getDeptId();
        busiDangerEntity.setName(user.getRealName());
        SysDept sysDept = deptService.getById(deptId);
        String detpName = sysDept.getName();
        busiDangerEntity.setDetp(detpName);
        String now = DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN);
        busiDangerEntity.setCreateTime(now);
        busiDangerEntity.setUpdateTime(now);

        this.save(busiDangerEntity);
    }
}